home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / netzwerk / pronet / pronet20.lha / ProNET / source / dospackets.s < prev    next >
Text File  |  1995-06-22  |  2KB  |  104 lines

  1. * Routines for handling DosPackets
  2.  
  3. ; -- Create a StandardPacket
  4. CreateStdPacket    ; RETURNS d0 *StandardPacket or NULL
  5.         movem.l    a2-a6,-(sp)
  6.         move.l    4.w,a6
  7.         move.l    #sp_SIZEOF,d0
  8.         move.l    #MEMF_PUBLIC,d1
  9.         LIBCALL    AllocMem
  10.         tst.l    d0
  11.         beq.s    csp_nomem
  12.         move.l    d0,a2
  13.         bsr    CreatePort
  14.         move.l    d0,sp_Msg+MN_REPLYPORT(a2)
  15.         beq.s    csp_noport
  16.         lea    sp_Pkt(a2),a3
  17.         move.l    a3,sp_Msg+LN_NAME(a2)
  18.         move.l    a2,sp_Pkt+dp_Link(a2)
  19.         move.l    a2,d0
  20.         movem.l    (sp)+,a2-a6
  21.         rts
  22.  
  23. ; -- Deallocate a StandardPacket got by CreateStdPacket
  24. DeleteStdPacket    ; a0 *StandardPacket
  25.         movem.l    a2-a6,-(sp)
  26.         move.l    4.w,a6
  27.         move.l    a0,a2
  28.         move.l    sp_Msg+MN_REPLYPORT(a2),a0
  29.         bsr    DeletePort
  30. csp_noport    move.l    a2,a1
  31.         move.l    #sp_SIZEOF,d0
  32.         LIBCALL    FreeMem
  33. csp_nomem    movem.l    (sp)+,a2-a6
  34.         moveq    #0,d0
  35.         rts
  36.  
  37. ; -- Send a StandardPacket to a MsgPort
  38. SendStdPkt    ; a0 *MsgPort
  39.         ; a1 *StandardPacket
  40.         move.l    a6,-(sp)
  41.         move.l    4.w,a6
  42.         move.l    sp_Msg+MN_REPLYPORT(a1),sp_Pkt+dp_Port(a1)
  43.         LIBCALL    PutMsg
  44.         move.l    (sp)+,a6
  45.         rts
  46.  
  47. ; -- Send a StandardPacket to a MsgPort, wait for return and get results
  48. SyncStdPkt    ; a0 *MsgPort
  49.         ; a1 *StandardPacket
  50.         ; RETURNS d0 dp_Res1
  51.         ;         d1 dp_Res2
  52.         move.l    a1,-(sp)
  53.         bsr    SendStdPkt
  54.         move.l    (sp)+,a0
  55.         bra    WaitStdPkt
  56.  
  57. ; -- Wait for return of the packet and get results
  58. WaitStdPkt    ; a0 *StandardPacket
  59.         ; RETURNS d0 dp_Res1
  60.         ;      d1 dp_Res2
  61.         movem.l    a2/a6,-(sp)
  62.         move.l    4.w,a6
  63.         move.l    a0,a2
  64.         move.l    sp_Msg+MN_REPLYPORT(a2),a0
  65.         LIBCALL    WaitPort
  66.         move.l    sp_Msg+MN_REPLYPORT(a2),a0
  67.         LIBCALL    GetMsg
  68.         move.l    sp_Pkt+dp_Res1(a2),d0
  69.         move.l    sp_Pkt+dp_Res2(a2),d1
  70.         movem.l    (sp)+,a2/a6
  71.         rts
  72.  
  73. ; Get a packet from the process' messageport
  74. GetPacket    ; RETURNS d0 *DosPacket or NULL
  75.         movem.l    a2/a6,-(sp)
  76.         move.l    4.w,a6
  77.         move.l    ThisTask(a6),a0
  78.         lea    pr_MsgPort(a0),a0
  79.         LIBCALL    GetMsg
  80.         tst.l    d0
  81.         beq.s    .0
  82.         move.l    d0,a0
  83.         move.l    LN_NAME(a0),d0
  84. .0        movem.l    (sp)+,a2/a6
  85.         rts
  86.  
  87. ; Return packet got by GetPacket
  88. ReturnPacket    ; a0: *DosPacket
  89.         ; d0: long result1
  90.         ; d1: long result2
  91.         movem.l    a3/a6,-(sp)
  92.         move.l    4.w,a6
  93.         move.l    ThisTask(a6),a1
  94.         move.l    d0,dp_Res1(a0)
  95.         move.l    d1,dp_Res2(a0)
  96.         move.l    dp_Port(a0),d0
  97.         lea    pr_MsgPort(a1),a1
  98.         move.l    a1,dp_Port(a0)
  99.         move.l    dp_Link(a0),a1
  100.         move.l    d0,a0
  101.         LIBCALL    PutMsg
  102.         movem.l    (sp)+,a3/a6
  103.         rts
  104.